var express = require('express');
var app = express();
app.set('views', './views');
app.set('view engine', 'jade');

app.use(function(req, res, next) {
  console.log('%s %s', req.method, req.url);
  next();
});

app.use('/static', express.static(__dirname + '/static'));

app.use(function(err, req, res, next) {
	console.error(err.stack);
	res.status(500);
  	res.render('error', { error: err, title: "Error", message: "Error: " + err });
});

app.get('/', function (req, res) {
	res.render('index', { title: 'Hey', message: 'Hello there!'});
})

app.get('/hello.txt', function(req, res) {
  	res.send('Hello World');
});

app.get('/data', function(req, res) {
	var data = [
	    ['Year', 'Sales', 'Expenses2'],
	    ['2004',  1000,      400],
	    ['2005',  1170,      460],
	    ['2006',  660,       1120],
	    [new Date().getTime(),  1030,      540]
	  ]	
	res.json(data);
});


var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

